<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面向对象</title>
</head>

<body>

</body>
<script>
    /*     // 1、对象工厂
        function person(name, age, sex) {
            return {
                name,
                age,
                sex
            }
        }
        let marry = new person("marry", 12, "girl")
        console.log(marry); */

    /*     // 2、构造函数
        function person(name, age, sex) {
            this.name = name;
            this.age = age;
            this.sex = sex
            this.say = function () {
                console.log(this.name + "你好")
            }
        }
        let marry = new person("marry", 12, "girl")
        console.log(marry);
        marry.say()
        console.log(marry.constructor == person);
        console.log(marry instanceof person); */

    /*     // 3、原型
        function person(name, age, sex) {
            this.name = name;
            this.age = age;
            this.sex = sex
        }
        person.prototype.say = function () {
            console.log(this.name + "你好")
        }
        let marry = new person("marry", 12, "girl")
        console.log(marry);
        marry.say() */

    // 4、原型扩展
    function person(name, age, sex) {
        this.name = name;
        this.age = age;
        this.sex = sex
    }
    person.prototype.say = function () {
        console.log(this.name + "你好")
    }
    person.prototype.from = "China"
    let marry = new person("marry", 12, "girl")
    console.log(marry, marry.from);
    marry.say()
    let tom = new person("tom", 13, "boy")
    tom.from = "USA"
    console.log(tom, tom.from);
    tom.say()
    // 判断可枚举属性
    console.log('marry', Object.keys(marry));
    console.log('marry', Object.getOwnPropertyNames(marry));
    // 判断可枚举属性和继承属性
    console.log('from' in marry);
    // new person原理
    // 1、 创建一个空对象
    // 2、赋予prototype
    // 3、赋予this
    // 4、添加属性
    // 5、返回新对象
</script>
</script>

</html>